package com.gking.aiService.realm;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.AuthenticationListener;
import org.apache.shiro.subject.PrincipalCollection;

@Slf4j
public class MyAuthenticationListener implements AuthenticationListener {

    @Override
    public void onSuccess(AuthenticationToken token, AuthenticationInfo info) {
        log.info("用户 " + token.getPrincipal() + " 在 Realm " + info.getPrincipals().getRealmNames() + " 中认证成功");
    }

    @Override
    public void onFailure(AuthenticationToken token, AuthenticationException ae) {
        log.warn("用户 " + token.getPrincipal() + " 在 Realm 中认证失败: " + ae.getMessage());
    }

    @Override
    public void onLogout(PrincipalCollection principals) {
        log.info("用户 " + principals.getPrimaryPrincipal() + " 已注销");
    }
}

